<?php
/*****************************************************************************
 *                                                                           *
 * Shop-Script PREMIUM                                                       *
 * Copyright (c) 2005 WebAsyst LLC. All rights reserved.                     *
 *                                                                           *
 *****************************************************************************/
?><?php
	// category navigation form
//	if ( isset($categoryID) )
//		$out = catGetCategoryCompactCList( $categoryID );
//	else
//		$out = catGetCategoryCompactCList( 1 );

    $res=mysql_query("SELECT * from ".CATEGORIES_TABLE);
    while($row=mysql_fetch_assoc($res)){
        if($row['parent']>1){
            if($qwe[$row['parent']]['parent']>1) 
                $row['level']=3;
            else $row['level']=2;
        }else $row['level']=1;
		
		if (is_string($qwe[$row['parent']])) {
			return;
		}
        
        $qwe[$row['parent']]['is_parent']='1';

        if ($row['categoryID']==115)
            $row['lnk']="/catalog/shoes/";
        elseif ($row['categoryID']==85)
            $row['lnk']="/catalog/suite/newyear.html";
        elseif ($row['categoryID']==90)
            $row['lnk']="/catalog/suite/halloween.html";
        elseif ($row['categoryID']==94)
            $row['lnk']="/portfolio/folkler.html";
        elseif ($row['categoryID']==99)
            $row['lnk']="/catalog/trenirovochnaya/";
        elseif ($row['categoryID']==84)
            $row['lnk']="/catalog/suite/heroy.html";
        elseif ($row['categoryID']==86)
            $row['lnk']="/catalog/suite/animals.html";
        elseif ($row['categoryID']==103)
            $row['lnk']="/catalog/suite/army.html";
        elseif ($row['categoryID']==111)
            $row['lnk']="/catalog/wigs/";
        elseif ($row['categoryID']==137)  
            $row['lnk']="/larus/city.html";
        elseif ($row['categoryID']==136)
            $row['lnk']="/graduation/graduation.html";
        elseif ($row['categoryID']==138)
            $row['lnk']="/portfolio/national.html";
        elseif ($row['categoryID']==139)
            $row['lnk']="/graduation/princes.html";
        elseif ($row['categoryID']==134)
            $row['lnk']="/scool/";
        else       
            $row['lnk']='/index.php?categoryID='.$row['categoryID'];
        
        if($row['categoryID']!=1) $qwe[$row['categoryID']]=$row;
    }

    function asd($a, $b){return $a['sort_order'] > $b['sort_order'] ? 1 : -1;}
    usort($qwe, asd);

    foreach($qwe as $idd=>$qwww){
        if(($qwww['sort_order']==0)&&($qwww['level']>1)){
            $qwe[]=$qwww;
            unset($qwe[$idd]);
        }
    }

    foreach($qwe as $i=>$qw){
        if(($qw['parent']==1)&&($qw['name']!='')) $out[]=$qw;
        foreach($qwe as $id=>$qww){
            if($qww['parent']==$qw['categoryID']){
                $out[]=$qww;
                foreach($qwe as $idd=>$qwww){
                    if($qwww['parent']==$qww['categoryID']){
                        $out[]=$qwww;
                        unset($qwe[$idd]);
                    }
                }
            }
        }
    }   
   
    $out=array_reverse($out);
    
    foreach($out as $id=>$item)        
        if($out[$id+1]['categoryID']==$out[$id]['parent']) $out[$id+1]['lnk']=$out[$id]['lnk'];
    
    $out=array_reverse($out);
       
	$smarty->assign( "categories_tree", $out );
?>